package coms.mianshi.serializable;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @program: item_02
 * @description: Teacher
 * 如果一个可序列化的类的成员不是基本类型，也不是String类型，那这个引用类型也必须是可序列化的；
 * 否则，会导致此类不能序列化.
 * @author: LL
 * @create: 2021-03-02 18:03
 */
public class Teacher implements Serializable {
    private String name;
    private Person person;

    public Teacher(final String name, final Person person) {
        this.name = name;
        this.person = person;
    }

    public static void main(final String[] args) throws IOException {
        final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\a.txt"));
        final Person person = new Person("效力", 40);
        final Teacher teacher = new Teacher("乐儿", person);
        oos.writeObject(teacher);
    }
}
